package com.ai.zhly.service;

import java.util.List;
import java.util.Map;

import com.ai.dmc.index.base.impl.base.BaseServiceImpl;
import com.ai.dmc.index.base.sequence.SequenceGenerator;
import com.ai.dmc.index.common.exception.BusinessException;
import com.ai.dmc.utils.json.JsonUtil;
import com.ai.frame.bean.InputObject;
import com.ai.frame.bean.OutputObject;
import com.ai.frame.logger.Logger;
import com.ai.frame.logger.LoggerFactory;

/**
 * @Description: 景区月排名
 * @date 2016年7月26日
 */
public class TourisRankServiceImpl extends BaseServiceImpl
		implements ITourisRankServiceImpl {
	// 定义对应Mapper文件的命名空间
	private static final String NAMESPACE = "touristRank.";
	private static final int TOPNUM = 5;
	public static Logger log = LoggerFactory
			.getServiceLog(TourisRankServiceImpl.class);

	private SequenceGenerator sequenceGenerator;

	private ICommonService commonService;

	public void setSequenceGenerator(SequenceGenerator sequenceGenerator) {
		this.sequenceGenerator = sequenceGenerator;
	}

	public void setCommonService(ICommonService commonService) {
		this.commonService = commonService;
	}

	@Override
	public void comfRankingLevel(InputObject inputObject,
			OutputObject outputObject) throws BusinessException {

		List<Map<String, String>> lResult = getBaseDao().queryForList(
				NAMESPACE + "comfRankingLevel", inputObject.getParams());
		int length = lResult.size();
		if (length != 0) {
			if (length < TOPNUM) {
				outputObject.setBeans(JsonUtil.Object2Json(lResult));
			} else {
				List<Map<String, String>> subList = lResult.subList(0, TOPNUM);
				outputObject.setBeans(JsonUtil.Object2Json(subList));
			}
		} else {
			outputObject.setBeans(JsonUtil.Object2Json(lResult));
		}

	}

	@Override
	public void welcomeRankingLevel(InputObject inputObject,
			OutputObject outputObject) throws BusinessException {
		List<Map<String, String>> lResult = getBaseDao().queryForList(
				NAMESPACE + "welcomeRankingLevel", inputObject.getParams());
		int length = lResult.size();
		if (length != 0) {
			if (length < TOPNUM) {
				outputObject.setBeans(JsonUtil.Object2Json(lResult));
			} else {
				List<Map<String, String>> subList = lResult.subList(0, TOPNUM);
				outputObject.setBeans(JsonUtil.Object2Json(subList));
			}
		} else {
			outputObject.setBeans(JsonUtil.Object2Json(lResult));
		}
	}

	@Override
	public void searchRankingLevel(InputObject inputObject,
			OutputObject outputObject) throws BusinessException {
		List<Map<String, String>> lResult = getBaseDao().queryForList(
				NAMESPACE + "searchRankingLevel", inputObject.getParams());
		int length = lResult.size();
		if (length != 0) {
			if (length < TOPNUM) {
				outputObject.setBeans(JsonUtil.Object2Json(lResult));
			} else {
				List<Map<String, String>> subList = lResult.subList(0, TOPNUM);
				outputObject.setBeans(JsonUtil.Object2Json(subList));
			}
		} else {
			outputObject.setBeans(JsonUtil.Object2Json(lResult));
		}

	}

	@Override
	public void evaluateRankingLevel(InputObject inputObject,
			OutputObject outputObject) throws BusinessException {
		List<Map<String, String>> lResult = getBaseDao().queryForList(
				NAMESPACE + "evaluateRankingLevel", inputObject.getParams());
		int length = lResult.size();
		if (length != 0) {
			if (length < TOPNUM) {
				outputObject.setBeans(JsonUtil.Object2Json(lResult));
			} else {
				List<Map<String, String>> subList = lResult.subList(0, TOPNUM);
				outputObject.setBeans(JsonUtil.Object2Json(subList));
			}
		} else {
			outputObject.setBeans(JsonUtil.Object2Json(lResult));
		}
	}

}
